<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Ereisma DataBase!</title>

</head>
<body>

<?php
function cosineSimilarity($tokensA, $tokensB)
{
    $a = $b = $c = 0;
    $uniqueTokensA = $uniqueTokensB = array();

    $uniqueMergedTokens = array_unique(array_merge($tokensA, $tokensB));

    foreach ($tokensA as $token) $uniqueTokensA[$token] = 0;
    foreach ($tokensB as $token) $uniqueTokensB[$token] = 0;

	document.write($uniqueTokensA[1]);

    foreach ($uniqueMergedTokens as $token) {
        $x = isset($uniqueTokensA[$token]) ? 1 : 0;
        $y = isset($uniqueTokensB[$token]) ? 1 : 0;
        $a += $x * $y;
        $b += $x;
        $c += $y;
    }
    return $b * $c != 0 ? $a / sqrt($b * $c) : 0;

}



?>

apotelesma:
<?php
$tok1[0]= "uoa";
$tok1[1]= "athens";
$tok1[2]= "di";
$tok1[3]= "telecom";
$tok1[4]= "inform2";

$tok2[0]= "ntua";
$tok2[1]= "athens";
$tok2[2]= "inform";
$tok2[3]= "elctr";
$tok2[4]= "engin";
$tok2[5]= "engin2";

echo cosineSimilarity($tok1, $tok2);
?>

</body>